import pytest,requests
from faker import Faker
faker = Faker(locale='zh_cn')
name = faker.name()
list_id = []
class Test_bu2():
    @pytest.fixture(scope="function",autouse=True)
    def setup_teardown(self):
        response = requests.post("https://jxc.tao51d.com/api/oauth/token?grant_type=password",
                                 headers={"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",
                                 "Authorization":"Basic YnVlcnl1bl9wYzpidWVyeXVuX3Bj"},
                                 data={"username": "15940624889", "password": "Aa123456!"})
        self.token = response.json()['access_token']

    def test_add(self):
         response1 = requests.post("https://jxc.tao51d.com/api/goodCat/saveData",headers={"Authorization":"Bearer "+str(self.token),
                      "Content-Type":"application/json; charset=UTF-8"},json={"id":"null","pid":"1697200105314189314","name":"qb"+str(name)})
         assert response1.json()['title'] == "保存成功！"
         list_id.append(response1.json()['data']['id'])
    def test_del(self):
        response2 = requests.delete("https://jxc.tao51d.com/api/goodCat/delete",headers={"Authorization":"Bearer "+str(self.token),
                      "Content-Type":"application/json; charset=UTF-8"},json= int(list_id[0]))
        assert response2.status_code == 200

